﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Enterprise.Management.Data;
using Enterprise.Management.Business;
using Enterprise.Management.ViewModels;
using Enterprise.Management.Caches;

namespace Enterprise.Management.Controllers
{
    public class BIController : BaseController
    {
        //
        // GET: /BI/

        BIBLL bllBI = new BIBLL();
        OperationHistoryBLL bllOperationHistory = new OperationHistoryBLL();

        public ActionResult Index()
        {
            DP_Basic_Info dp_basic_info = bllBI.GetBasicInfo(BranchCategoryCache.BranchCategoryId.Value);
            BIViewModel vmBI = new BIViewModel();
            
            if (dp_basic_info != null)
            {
                vmBI.isNew = false;
                vmBI.BscInf_Address = dp_basic_info.BscInf_Address;
                vmBI.BscInf_Area = dp_basic_info.BscInf_Area.Value;
                vmBI.BscInf_Bianma = dp_basic_info.BscInf_Bianma;
                vmBI.BscInf_BrokerNum = dp_basic_info.BscInf_BrokerNum;
                vmBI.BscInf_DeptLevel = dp_basic_info.BscInf_DeptLevel;
                vmBI.BscInf_DeptName = dp_basic_info.BscInf_DeptName;
                vmBI.BscInf_DeputyManagerDangPifuDate = dp_basic_info.BscInf_DeputyManagerDangPifuDate;
                vmBI.BscInf_DeputyManagerEmail = dp_basic_info.BscInf_DeputyManagerEmail;
                vmBI.BscInf_DeputyManagerMobile = dp_basic_info.BscInf_DeputyManagerMobile;
                vmBI.BscInf_DeputyManagerName = dp_basic_info.BscInf_DeputyManagerName;
                vmBI.BscInf_DeputyManagerTel = dp_basic_info.BscInf_DeputyManagerTel;
                vmBI.BscInf_DijiXzq = dp_basic_info.BscInf_DijiXzq;
                vmBI.BscInf_DOB = dp_basic_info.BscInf_DOB;
                vmBI.BscInf_EmpTotalNum = dp_basic_info.BscInf_EmpTotalNum;
                vmBI.BscInf_Fax = dp_basic_info.BscInf_Fax;
                vmBI.BscInf_InovationBusinessContactEmail = dp_basic_info.BscInf_InovationBusinessContactEmail;
                vmBI.BscInf_InovationBusinessContactMobile = dp_basic_info.BscInf_InovationBusinessContactMobile;
                vmBI.BscInf_InovationBusinessContactName = dp_basic_info.BscInf_InovationBusinessContactName;
                vmBI.BscInf_InovationBusinessContactTel = dp_basic_info.BscInf_InovationBusinessContactTel;
                vmBI.BscInf_InvestAdvisorDangPifuDate = dp_basic_info.BscInf_InvestAdvisorDangPifuDate;
                vmBI.BscInf_InvestAdvisorDirectorEmail = dp_basic_info.BscInf_InvestAdvisorDirectorEmail;
                vmBI.BscInf_InvestAdvisorDirectorMobile = dp_basic_info.BscInf_InvestAdvisorDirectorMobile;
                vmBI.BscInf_InvestAdvisorDirectorName = dp_basic_info.BscInf_InvestAdvisorDirectorName;
                vmBI.BscInf_InvestAdvisorDirectorTel = dp_basic_info.BscInf_InvestAdvisorDirectorTel;
                vmBI.BscInf_InvestAdvisorNum = dp_basic_info.BscInf_InvestAdvisorNum;
                vmBI.BscInf_JichuBianzhi = dp_basic_info.BscInf_JichuBianzhi;
                vmBI.BscInf_JigouBianma = dp_basic_info.BscInf_JigouBianma;
                vmBI.BscInf_JingjirenYewuDate = dp_basic_info.BscInf_JingjirenYewuDate.Value;
                vmBI.BscInf_KuozhanBianzhi = dp_basic_info.BscInf_KuozhanBianzhi;
                vmBI.BscInf_ManagerDangPifuDate = dp_basic_info.BscInf_ManagerDangPifuDate;
                vmBI.BscInf_ManagerEmail = dp_basic_info.BscInf_ManagerEmail;
                vmBI.BscInf_ManagerMobile = dp_basic_info.BscInf_ManagerMobile;
                vmBI.BscInf_ManagerName = dp_basic_info.BscInf_ManagerName;
                vmBI.BscInf_ManagerTel = dp_basic_info.BscInf_ManagerTel;
                vmBI.BscInf_MarketDirectorDangPifuDate = dp_basic_info.BscInf_MarketDirectorDangPifuDate;
                vmBI.BscInf_MarketDirectorEmail = dp_basic_info.BscInf_MarketDirectorEmail;
                vmBI.BscInf_MarketDirectorMobile = dp_basic_info.BscInf_MarketDirectorMobile;
                vmBI.BscInf_MarketDirectorName = dp_basic_info.BscInf_MarketDirectorName;
                vmBI.BscInf_MarketDirectorTel = dp_basic_info.BscInf_MarketDirectorTel;
                vmBI.BscInf_MarketingNum = dp_basic_info.BscInf_MarketingNum;
                vmBI.BscInf_OfficialStaffNum = dp_basic_info.BscInf_OfficialStaffNum;
                vmBI.BscInf_OperationDirectorDangPifuDate = dp_basic_info.BscInf_OperationDirectorDangPifuDate;
                vmBI.BscInf_OperationDirectorEmail = dp_basic_info.BscInf_OperationDirectorEmail;
                vmBI.BscInf_OperationDirectorMobile = dp_basic_info.BscInf_OperationDirectorMobile;
                vmBI.BscInf_OperationDirectorName = dp_basic_info.BscInf_OperationDirectorName;
                vmBI.BscInf_OperationDirectorTel = dp_basic_info.BscInf_OperationDirectorTel;
                vmBI.BscInf_QihuoIBDate = dp_basic_info.BscInf_QihuoIBDate.Value;
                vmBI.BscInf_RntlPrpt = dp_basic_info.BscInf_RntlPrpt;
                vmBI.BscInf_ServiceWorkerNum = dp_basic_info.BscInf_ServiceWorkerNum;
                vmBI.BscInf_ShuangRongDate = dp_basic_info.BscInf_ShuangRongDate.Value;
                vmBI.BscInf_TelCmpl = dp_basic_info.BscInf_TelCmpl;
                vmBI.BscInf_TelCnsl = dp_basic_info.BscInf_TelCnsl;
                vmBI.BscInf_TelDlgt = dp_basic_info.BscInf_TelDlgt;
                vmBI.BscInf_XianjiXzq= dp_basic_info.BscInf_XianjiXzq;
                vmBI.BscInf_Xiaqu = dp_basic_info.BscInf_Xiaqu;
                vmBI.BscInf_ZipCode = dp_basic_info.BscInf_ZipCode;
            }
            else
            {
                vmBI.isNew = true;
            }
            return View(vmBI);
        }

        public ActionResult Create()
        {
            return View();
        }

        [HttpPost]
        public ActionResult Create(CreateBIViewModel vmCreateBI)
        {
            if (ModelState.IsValid)
            {
                DP_User dp_user = bllBI.GetUser(BranchCategoryCache.BranchCategoryId.Value);

                DP_Basic_Info dp_basic_info = new DP_Basic_Info();
                dp_basic_info.BscInf_CtgrID = BranchCategoryCache.BranchCategoryId.Value;
                dp_basic_info.BscInf_Address = vmCreateBI.BscInf_Address;
                dp_basic_info.BscInf_Area = vmCreateBI.BscInf_Area;
                dp_basic_info.BscInf_Bianma = vmCreateBI.BscInf_Bianma;
                dp_basic_info.BscInf_BrokerNum = vmCreateBI.BscInf_BrokerNum;
                dp_basic_info.BscInf_DeptLevel = vmCreateBI.BscInf_DeptLevel;
                dp_basic_info.BscInf_DeptName = vmCreateBI.BscInf_DeptName;
                dp_basic_info.BscInf_DeputyManagerDangPifuDate = vmCreateBI.BscInf_DeputyManagerDangPifuDate;
                dp_basic_info.BscInf_DeputyManagerEmail = vmCreateBI.BscInf_DeputyManagerEmail;
                dp_basic_info.BscInf_DeputyManagerMobile = vmCreateBI.BscInf_DeputyManagerMobile;
                dp_basic_info.BscInf_DeputyManagerName = vmCreateBI.BscInf_DeputyManagerName;
                dp_basic_info.BscInf_DeputyManagerTel = vmCreateBI.BscInf_DeputyManagerTel;
                dp_basic_info.BscInf_DijiXzq = vmCreateBI.BscInf_DijiXzq;
                dp_basic_info.BscInf_DOB = vmCreateBI.BscInf_DOB;
                dp_basic_info.BscInf_EmpTotalNum = vmCreateBI.BscInf_EmpTotalNum;
                dp_basic_info.BscInf_Fax = vmCreateBI.BscInf_Fax;
                dp_basic_info.BscInf_InovationBusinessContactEmail = vmCreateBI.BscInf_InovationBusinessContactEmail;
                dp_basic_info.BscInf_InovationBusinessContactMobile = vmCreateBI.BscInf_InovationBusinessContactMobile;
                dp_basic_info.BscInf_InovationBusinessContactName = vmCreateBI.BscInf_InovationBusinessContactName;
                dp_basic_info.BscInf_InovationBusinessContactTel = vmCreateBI.BscInf_InovationBusinessContactTel;
                dp_basic_info.BscInf_InvestAdvisorDangPifuDate = vmCreateBI.BscInf_InvestAdvisorDangPifuDate;
                dp_basic_info.BscInf_InvestAdvisorDirectorEmail = vmCreateBI.BscInf_InvestAdvisorDirectorEmail;
                dp_basic_info.BscInf_InvestAdvisorDirectorMobile = vmCreateBI.BscInf_InvestAdvisorDirectorMobile;
                dp_basic_info.BscInf_InvestAdvisorDirectorName = vmCreateBI.BscInf_InvestAdvisorDirectorName;
                dp_basic_info.BscInf_InvestAdvisorDirectorTel = vmCreateBI.BscInf_InvestAdvisorDirectorTel;
                dp_basic_info.BscInf_InvestAdvisorNum = vmCreateBI.BscInf_InvestAdvisorNum;
                dp_basic_info.BscInf_JichuBianzhi = vmCreateBI.BscInf_JichuBianzhi;
                dp_basic_info.BscInf_JigouBianma = vmCreateBI.BscInf_JigouBianma;
                dp_basic_info.BscInf_JingjirenYewuDate = vmCreateBI.BscInf_JingjirenYewuDate;
                dp_basic_info.BscInf_KuozhanBianzhi = vmCreateBI.BscInf_KuozhanBianzhi;
                dp_basic_info.BscInf_ManagerDangPifuDate = vmCreateBI.BscInf_ManagerDangPifuDate;
                dp_basic_info.BscInf_ManagerEmail = vmCreateBI.BscInf_ManagerEmail;
                dp_basic_info.BscInf_ManagerMobile = vmCreateBI.BscInf_ManagerMobile;
                dp_basic_info.BscInf_ManagerName = vmCreateBI.BscInf_ManagerName;
                dp_basic_info.BscInf_ManagerTel = vmCreateBI.BscInf_ManagerTel;
                dp_basic_info.BscInf_MarketDirectorDangPifuDate = vmCreateBI.BscInf_MarketDirectorDangPifuDate;
                dp_basic_info.BscInf_MarketDirectorEmail = vmCreateBI.BscInf_MarketDirectorEmail;
                dp_basic_info.BscInf_MarketDirectorMobile = vmCreateBI.BscInf_MarketDirectorMobile;
                dp_basic_info.BscInf_MarketDirectorName = vmCreateBI.BscInf_MarketDirectorName;
                dp_basic_info.BscInf_MarketDirectorTel = vmCreateBI.BscInf_MarketDirectorTel;
                dp_basic_info.BscInf_MarketingNum = vmCreateBI.BscInf_MarketingNum;
                dp_basic_info.BscInf_OfficialStaffNum = vmCreateBI.BscInf_OfficialStaffNum;
                dp_basic_info.BscInf_OperationDirectorDangPifuDate = vmCreateBI.BscInf_OperationDirectorDangPifuDate;
                dp_basic_info.BscInf_OperationDirectorEmail = vmCreateBI.BscInf_OperationDirectorEmail;
                dp_basic_info.BscInf_OperationDirectorMobile = vmCreateBI.BscInf_OperationDirectorMobile;
                dp_basic_info.BscInf_OperationDirectorName = vmCreateBI.BscInf_OperationDirectorName;
                dp_basic_info.BscInf_OperationDirectorTel = vmCreateBI.BscInf_OperationDirectorTel;
                dp_basic_info.BscInf_QihuoIBDate = vmCreateBI.BscInf_QihuoIBDate;
                dp_basic_info.BscInf_RntlPrpt = vmCreateBI.BscInf_RntlPrpt;
                dp_basic_info.BscInf_ServiceWorkerNum = vmCreateBI.BscInf_ServiceWorkerNum;
                dp_basic_info.BscInf_ShuangRongDate = vmCreateBI.BscInf_ShuangRongDate;
                dp_basic_info.BscInf_TelCmpl = vmCreateBI.BscInf_TelCmpl;
                dp_basic_info.BscInf_TelCnsl = vmCreateBI.BscInf_TelCnsl;
                dp_basic_info.BscInf_TelDlgt = vmCreateBI.BscInf_TelDlgt;
                dp_basic_info.BscInf_XianjiXzq= vmCreateBI.BscInf_XianjiXzq;
                dp_basic_info.BscInf_Xiaqu = vmCreateBI.BscInf_Xiaqu;
                dp_basic_info.BscInf_ZipCode = vmCreateBI.BscInf_ZipCode;
                dp_basic_info.ModifiedBy = HtmlCache.GetUser().User_ID;
                dp_basic_info.ModifiedDate = DateTime.Today;
                bllBI.AddBasicInfo(dp_basic_info);

                DP_Operation_History dp_operation_history = new DP_Operation_History();
                dp_operation_history.OprHis_CtgrID = BranchCategoryCache.BranchCategoryId.Value;
                dp_operation_history.OprHis_TypeID = (int)FunctionType.BI;
                dp_operation_history.OprHis_Date = DateTime.Today;
                dp_operation_history.OprHis_Comment = "新建";
                bllOperationHistory.AddOperationHistory(dp_operation_history);
            }
            return View(vmCreateBI);
        }

        public ActionResult Edit()
        {
            DP_Basic_Info dp_basic_info = bllBI.GetBasicInfo(BranchCategoryCache.BranchCategoryId.Value);
            UpdateBIViewModel vmUpdateBI = new UpdateBIViewModel();

            if (dp_basic_info != null)
            {
                vmUpdateBI.BscInf_Address = dp_basic_info.BscInf_Address;
                vmUpdateBI.BscInf_Area = dp_basic_info.BscInf_Area.Value;
                vmUpdateBI.BscInf_Bianma = dp_basic_info.BscInf_Bianma;
                vmUpdateBI.BscInf_BrokerNum = dp_basic_info.BscInf_BrokerNum;
                vmUpdateBI.BscInf_DeptLevel = dp_basic_info.BscInf_DeptLevel;
                vmUpdateBI.BscInf_DeptName = dp_basic_info.BscInf_DeptName;
                vmUpdateBI.BscInf_DeputyManagerDangPifuDate = dp_basic_info.BscInf_DeputyManagerDangPifuDate;
                vmUpdateBI.BscInf_DeputyManagerEmail = dp_basic_info.BscInf_DeputyManagerEmail;
                vmUpdateBI.BscInf_DeputyManagerMobile = dp_basic_info.BscInf_DeputyManagerMobile;
                vmUpdateBI.BscInf_DeputyManagerName = dp_basic_info.BscInf_DeputyManagerName;
                vmUpdateBI.BscInf_DeputyManagerTel = dp_basic_info.BscInf_DeputyManagerTel;
                vmUpdateBI.BscInf_DijiXzq = dp_basic_info.BscInf_DijiXzq;
                vmUpdateBI.BscInf_DOB = dp_basic_info.BscInf_DOB;
                vmUpdateBI.BscInf_EmpTotalNum = dp_basic_info.BscInf_EmpTotalNum;
                vmUpdateBI.BscInf_Fax = dp_basic_info.BscInf_Fax;
                vmUpdateBI.BscInf_InovationBusinessContactEmail = dp_basic_info.BscInf_InovationBusinessContactEmail;
                vmUpdateBI.BscInf_InovationBusinessContactMobile = dp_basic_info.BscInf_InovationBusinessContactMobile;
                vmUpdateBI.BscInf_InovationBusinessContactName = dp_basic_info.BscInf_InovationBusinessContactName;
                vmUpdateBI.BscInf_InovationBusinessContactTel = dp_basic_info.BscInf_InovationBusinessContactTel;
                vmUpdateBI.BscInf_InvestAdvisorDangPifuDate = dp_basic_info.BscInf_InvestAdvisorDangPifuDate;
                vmUpdateBI.BscInf_InvestAdvisorDirectorEmail = dp_basic_info.BscInf_InvestAdvisorDirectorEmail;
                vmUpdateBI.BscInf_InvestAdvisorDirectorMobile = dp_basic_info.BscInf_InvestAdvisorDirectorMobile;
                vmUpdateBI.BscInf_InvestAdvisorDirectorName = dp_basic_info.BscInf_InvestAdvisorDirectorName;
                vmUpdateBI.BscInf_InvestAdvisorDirectorTel = dp_basic_info.BscInf_InvestAdvisorDirectorTel;
                vmUpdateBI.BscInf_InvestAdvisorNum = dp_basic_info.BscInf_InvestAdvisorNum;
                vmUpdateBI.BscInf_JichuBianzhi = dp_basic_info.BscInf_JichuBianzhi;
                vmUpdateBI.BscInf_JigouBianma = dp_basic_info.BscInf_JigouBianma;
                vmUpdateBI.BscInf_JingjirenYewuDate = dp_basic_info.BscInf_JingjirenYewuDate.Value;
                vmUpdateBI.BscInf_KuozhanBianzhi = dp_basic_info.BscInf_KuozhanBianzhi;
                vmUpdateBI.BscInf_ManagerDangPifuDate = dp_basic_info.BscInf_ManagerDangPifuDate;
                vmUpdateBI.BscInf_ManagerEmail = dp_basic_info.BscInf_ManagerEmail;
                vmUpdateBI.BscInf_ManagerMobile = dp_basic_info.BscInf_ManagerMobile;
                vmUpdateBI.BscInf_ManagerName = dp_basic_info.BscInf_ManagerName;
                vmUpdateBI.BscInf_ManagerTel = dp_basic_info.BscInf_ManagerTel;
                vmUpdateBI.BscInf_MarketDirectorDangPifuDate = dp_basic_info.BscInf_MarketDirectorDangPifuDate;
                vmUpdateBI.BscInf_MarketDirectorEmail = dp_basic_info.BscInf_MarketDirectorEmail;
                vmUpdateBI.BscInf_MarketDirectorMobile = dp_basic_info.BscInf_MarketDirectorMobile;
                vmUpdateBI.BscInf_MarketDirectorName = dp_basic_info.BscInf_MarketDirectorName;
                vmUpdateBI.BscInf_MarketDirectorTel = dp_basic_info.BscInf_MarketDirectorTel;
                vmUpdateBI.BscInf_MarketingNum = dp_basic_info.BscInf_MarketingNum;
                vmUpdateBI.BscInf_OfficialStaffNum = dp_basic_info.BscInf_OfficialStaffNum;
                vmUpdateBI.BscInf_OperationDirectorDangPifuDate = dp_basic_info.BscInf_OperationDirectorDangPifuDate;
                vmUpdateBI.BscInf_OperationDirectorEmail = dp_basic_info.BscInf_OperationDirectorEmail;
                vmUpdateBI.BscInf_OperationDirectorMobile = dp_basic_info.BscInf_OperationDirectorMobile;
                vmUpdateBI.BscInf_OperationDirectorName = dp_basic_info.BscInf_OperationDirectorName;
                vmUpdateBI.BscInf_OperationDirectorTel = dp_basic_info.BscInf_OperationDirectorTel;
                vmUpdateBI.BscInf_QihuoIBDate = dp_basic_info.BscInf_QihuoIBDate.Value;
                vmUpdateBI.BscInf_RntlPrpt = dp_basic_info.BscInf_RntlPrpt;
                vmUpdateBI.BscInf_ServiceWorkerNum = dp_basic_info.BscInf_ServiceWorkerNum;
                vmUpdateBI.BscInf_ShuangRongDate = dp_basic_info.BscInf_ShuangRongDate.Value;
                vmUpdateBI.BscInf_TelCmpl = dp_basic_info.BscInf_TelCmpl;
                vmUpdateBI.BscInf_TelCnsl = dp_basic_info.BscInf_TelCnsl;
                vmUpdateBI.BscInf_TelDlgt = dp_basic_info.BscInf_TelDlgt;
                vmUpdateBI.BscInf_XianjiXzq= dp_basic_info.BscInf_XianjiXzq;
                vmUpdateBI.BscInf_Xiaqu = dp_basic_info.BscInf_Xiaqu;
                vmUpdateBI.BscInf_ZipCode = dp_basic_info.BscInf_ZipCode;
            }
            return View(vmUpdateBI);
        }

        [HttpPost]
        public ActionResult Edit(UpdateBIViewModel vmUpdateBI)
        {
            if (ModelState.IsValid)
            {
                vmUpdateBI.BscInf_CtgrID = BranchCategoryCache.BranchCategoryId.Value;
                bllBI.UpdateBasicInfo(vmUpdateBI);

                DP_Operation_History dp_operation_history = new DP_Operation_History();
                dp_operation_history.OprHis_CtgrID = BranchCategoryCache.BranchCategoryId.Value;
                dp_operation_history.OprHis_TypeID = (int)FunctionType.DependencyBranch;
                dp_operation_history.OprHis_Date = DateTime.Today;
                dp_operation_history.OprHis_Comment = "更新";
                bllOperationHistory.AddOperationHistory(dp_operation_history);
            }
            return View(vmUpdateBI);
        }
    }
}
